package view;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import model.kwalificatiebeheer.KwalificatieDossier;
import model.kwalificatiebeheer.KwalificatieDossiers;

public class KwalificatieDossierTableModel extends AbstractTableModel{
	
	private KwalificatieDossiers kds = KwalificatieDossiers.getInstance();
	private String[] columnNames = {"Crebo", "Sector", "Opleidings Domein", "Branch", "Geldig vanaf"};
	private ArrayList<KwalificatieDossier> kdList = kds.getKwalificatieDossiers();
	
	public KwalificatieDossierTableModel(){	}
	
	public String getColumnName(int col) {
		return columnNames[col];
	}
	
	@Override
	public int getColumnCount() {
		return 5;
	}

	@Override
	public int getRowCount() {
		return kdList.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		KwalificatieDossier row = kdList.get(rowIndex);
		if(columnIndex==0){
			if(row.getCrebos() != null){
				String crebos = "";
				Long[] creboList = row.getCrebos();
	        	for(int i =0; i < creboList.length; i++){
	        		if(i > 0){
	            		crebos = crebos + ", " + creboList[i];
	        		}else{
	        			crebos = ""+creboList[i];
	        		}
	        	}        	
	            return crebos;
        	}
        }
        else if(columnIndex==1){
        	return row.getSector();
        }
        else if(columnIndex==2){
        	return row.getDomain();
        }
        else if(columnIndex==3){
        	return row.getBranch();
        }
        else if(columnIndex==4){
        	return new Date(((long)row.getCohort())*1000L);
        }
        return null;
	}

}
